// Core Test Support
// Copyright 2004 (C) Ralph Thomas

#include "testCore.h"
#include <vector>
#include <string>
#include <iostream>

namespace test {
	basic::~basic() {}
	const char* basic::performTest() { return "unimplemented test"; }
	const char* basic::getTestName() { return "undefined test"; }


	class myRunner : public runnerSingleton {
	  private:
		std::vector<basic*> _tests;
		int _numFailed;
	  public:
		myRunner() : _numFailed( 0 ) {}

		virtual ~myRunner() {
			std::vector<basic*>::iterator i;
			for( i = _tests.begin(); i != _tests.end(); i++ )
				delete *i;
		}

		virtual void adoptTest( basic* t ) {
			_tests.push_back( t );
		}

		virtual void run() {
			std::vector<basic*>::iterator i;
			// Register our tests
			registerTests();

			// Now execute them
			for( i = _tests.begin(); i != _tests.end(); i++ ) {
				const char* passed = (*i)->performTest();
				std::string name = (*i)->getTestName();

				if( passed == NULL ) {
					std::cout << " " << name <<
					  " PASSED" << std::endl;
				} else {
					std::cout << " " << name <<
					  " FAILED (" << passed << ") " << std::endl;
					_numFailed++;
				}
			}

			// Summary
			std::cout << "SUMMARY: (" << _tests.size() - _numFailed << "/"
			  << _tests.size() << ") TEST PASSED"
			  << std::endl;
		}
		//
		/// Return the number of tests which failed.
		///
		/// \return the number of tests which failed.
		//
		int getFailureCount() const { return _numFailed; }
	};
};

int main() {
	test::myRunner runner;

	runner.run();

	return runner.getFailureCount();
}

